﻿using System.Web;
using Dost.Khcn.Biz;
using Dost.Khcn.Data.EntityModel;

namespace Dost.Khcn.Web.Common
{
    public class WebCommon
    {
        private static Employee _employee;
        public static Employee CurrrentEmployee
        {
            get
            {
                _employee = (Employee)HttpContext.Current.Session["CurrentEmployee"];
                if (_employee == null)
                {
                    if (HttpContext.Current.User != null)
                        _employee = new EmployeeBiz().GetByName(HttpContext.Current.User.Identity.Name);
                    HttpContext.Current.Session["CurrentEmployee"] = _employee;
                }
                return _employee;
            }

            set
            {
                if (value == null)
                {
                    HttpContext.Current.User = null;
                    HttpContext.Current.Session.Remove("CurrentEmployee");
                    return;
                }
                HttpContext.Current.Session["CurrentEmployee"] = value;
            }
        }

        public static string GetGlobalString(string key)
        {
            return (string)HttpContext.GetGlobalResourceObject("GlobalStrings", key);
        }
    }
}